﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class PhanTrang : System.Web.UI.Page
{
    ConnectionData cn = new ConnectionData();

    protected void Page_Load(object sender, EventArgs e)
    {
        TrangPhan();
    }

    public void TrangPhan()
    {
        string sql = "select dt.tieu_de, dt.mo_ta, dt.Id, do.Hinh_anh from dang_tin as dt, Dia_Oc as do where dt.dia_oc_id=do.Id order by id desc";

        DataSet ds = new DataSet();


        ds = cn.ExecuteQuery(sql);




        CollectionPager1.MaxPages = 10000;

        CollectionPager1.PageSize = 5; // số items hiển thị trên một trang



        CollectionPager1.DataSource = ds.Tables[0].DefaultView;

        CollectionPager1.BindToControl = DataListPhanTrang;

        DataListPhanTrang.DataSource = CollectionPager1.DataSourcePaged;

        DataListPhanTrang.DataBind();
    }
    protected void DataListPhanTrang_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        //tin tuc con
        Image img = default(Image);
        img = (Image)e.Item.FindControl("imgHinh");
        img.ImageUrl = "HinhDiaOc/" + Convert.ToString(((DataRowView)e.Item.DataItem)["Hinh_Anh"]);

        HyperLink tieude = default(HyperLink);
        tieude = (HyperLink)e.Item.FindControl("hplTieude");
        tieude.Text = Convert.ToString(((DataRowView)e.Item.DataItem)["Tieu_de"]);
        tieude.NavigateUrl = "Chitiettintuc?id=" + Convert.ToString(((DataRowView)e.Item.DataItem)["id"]);

        Label ndtt = default(Label);
        ndtt = (Label)e.Item.FindControl("lblNoidungtomtat");
        String nd = Convert.ToString(((DataRowView)e.Item.DataItem)["Mo_Ta"]);
        if (nd.Length > 200)
            ndtt.Text = nd.Substring(0, 200) + " ...";
        else
            ndtt.Text = nd.Substring(0, nd.Length) + " ...";
        //ket thuc tin tuc con

    }
}